<%-- 
    Document   : beers
    Created on : Mar 22, 2013, 11:03:48 AM
    Author     : thomasg
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@ include file="loginDetails.jsp" %>
<!DOCTYPE html>
<HTML>
<HEAD>
	<TITLE>Query Results Using JSP</TITLE>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</HEAD>
<BODY>
<% 
try { // Load driver class
	Class.forName("com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e) {
	System.err.println("ClassNotFoundException: " +e);
}
Connection con = null;
try { 
	
	con = DriverManager.getConnection(url+db, uid, pwd); 
	//defined in loginDetails.jsp
	
	Statement stmt = con.createStatement();
	ResultSet rst = stmt.executeQuery("SELECT b.name, b.manf FROM Beers b");
	out.print("<TABLE border=1><TR><TH>Beer</TH>");
	out.println("<TH>Manufacturer</TH></TR>");

	while (rst.next()){ 
		out.println("<TR><TD>"+rst.getString("name")+
			"</TD>"+"<TD>"+rst.getString("manf")+"</TD></TR>");
	}
	out.println("</TABLE>");
	con.close();
}
catch (SQLException ex) { System.err.println(ex); }
finally{ 
	if (con != null)
	try
	{ con.close(); }
	catch (SQLException ex) { System.err.println(ex); }
}

%>
</BODY>
</HTML>

